require('./Pagejdzfmain.less');
import Reflux from 'reflux';
import ReactMixin from 'react-mixin';
import Actions from './Actions'
import Store from './Store';
import { Button,Page, Panel,PanelHeader, PanelBody, PanelFooter,ButtonArea,
  MediaBox,Cells, Cell,CellHeader,MediaBoxTitle,MediaBoxHeader,
  MediaBoxDescription,MediaBoxBody,MediaBoxInfo,MediaBoxInfoMeta,
  CellBody,CellFooter,Toast, Form,FormCell,Radio,Gallery,GalleryDelete,
  Uploader,TextArea,ActionSheet,Flex,FlexItem,SearchBar} from  'react-weui/build/packages'
import {Control} from 'react-keeper';
import zhenggaitongzhi  from './../../../assets/img/整改通知.png';
import xingzhengchufa  from './../../../assets/img/行政处罚.png';
import chengxintongbao  from './../../../assets/img/诚信通报.png';
import tinggongtongzhi  from './../../../assets/img/停工通知.png';


class Jdzfmain extends React.Component {

  constructor(props) {
    super(props);
    this.handleSubmit=this.handleSubmit.bind(this);
    this.handleCancel=this.handleCancel.bind(this);
  }

  handleSubmit(text){
    Actions.handleSubmit(text);
  }

  handleCancel(){
    Actions.handleCancel();
  }

  render() {
    return (
      <div>
        <SearchBar onChange={this.handleSubmit}
                   onCancel={this.handleCancel}
                   defaultValue={this.state.jdzfmain.searchText}
                   placeholder="搜索工程"
        >

        </SearchBar>
        {
          this.state.jdzfmain.searchDivShow&&this.state.jdzfmain.searchData.length > 0&&
          <div className="searchDisDiv" onClick={this.handleCancel}>
            <Panel>
              <PanelBody>
                {this.state.jdzfmain.searchData.map((item,i)=>{
                  return (
                    <MediaBox type="appmsg" onClick={() =>
                    {Control.go('/jdzfhome/jdzfdetail',{dataDetail:item,
                      domain:this.state.jdzfmain.domain,
                      mediaUploadPath:this.state.jdzfmain.mediaUploadPath
                    })}}>
                      <MediaBoxHeader>
                        <img src={item.suggesttype==1?zhenggaitongzhi:
                          item.suggesttype==2?xingzhengchufa:
                            item.suggesttype==3?chengxintongbao:
                              item.suggesttype==4?tinggongtongzhi:null} style={{
                          width:30,
                          height:30,
                          marginTop:15
                        }}/>
                      </MediaBoxHeader>
                      <MediaBoxBody>
                        <MediaBoxTitle>{item.suggesttype==1?"整改通知":
                          item.suggesttype==2?"停工通知":
                            item.suggesttype==3?"行政处罚":
                              item.suggesttype==4?"诚信通报":""}</MediaBoxTitle>
                        <MediaBoxDescription>
                          {item.createTime}<br/>
                          <span className="pname">{item.title}</span>
                        </MediaBoxDescription>
                      </MediaBoxBody>
                    </MediaBox>
                  )
                })
                }

              </PanelBody>
            </Panel>
          </div>
        }
        {
          this.state.jdzfmain.pdata.length > 0 ?
            this.state.jdzfmain.pdata.map((item,i)=>{
              return (
                <Panel>
                  <PanelBody>
                    <MediaBox key={i} type="appmsg" onClick={() =>
                    {Control.go('/jdzfhome/jdzfdetail',{dataDetail:item
                    })}}>
                      <MediaBoxHeader>
                        <img src={item.suggesttype==1?zhenggaitongzhi:
                          item.suggesttype==2?xingzhengchufa:
                            item.suggesttype==3?chengxintongbao:
                              item.suggesttype==4?tinggongtongzhi:null} style={{
                          width:30,
                          height:30,
                          marginTop:15
                        }}/>
                      </MediaBoxHeader>
                      <MediaBoxBody>
                        <MediaBoxTitle>{item.suggesttype==1?"整改通知":
                          item.suggesttype==2?"停工通知":
                            item.suggesttype==3?"行政处罚":
                              item.suggesttype==4?"诚信通报":""}
                        </MediaBoxTitle>
                        <MediaBoxDescription>
                          {item.createTime}<br/>
                          <span className="pname">{item.title}</span>
                        </MediaBoxDescription>
                      </MediaBoxBody>
                    </MediaBox>
                  </PanelBody>
                  <PanelFooter onClick={() =>{Control.go("/jdzfhome/jdzflist",item.suggesttype)}}>
                    <Cell access link>
                      <CellBody>查看更多</CellBody>
                      <CellFooter />
                    </Cell>
                  </PanelFooter>
                </Panel>
              )
            })
            :
            <Panel>
              <PanelBody>
                <MediaBox>搜索不到结果</MediaBox>
              </PanelBody>
            </Panel>
        }
      </div>
    );
  }

  componentWillMount() {
    Actions.loadData();
  }

  componentDidMount() {

  }

  componentWillReceiveProps(nextProps) {

  }

  shouldComponentUpdate(nextProps, nextState) {
    const thisProps = this.props || {},
      thisState = this.state.jdzfmain || {};
    if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
      return true;
    }

    for (const key in nextProps) {
      if (thisProps[key] !== nextProps[key]) {
        console.log(thisProps[key], nextProps[key]);
        return true;
      }
    }

    for (const key in nextState) {
      if (thisState[key] !== nextState[key]) {
        return true;
      }
    }
    return false;
  }

}

ReactMixin.onClass(Jdzfmain, Reflux.connect(Store, 'jdzfmain'));


export default Jdzfmain ;
